package com.clas.liu.myapplication.presenter.impl;

import android.os.Handler;
import android.os.Message;

import com.clas.liu.myapplication.model.event.SquareEvent;
import com.clas.liu.myapplication.model.impl.BaseFragmentModel;
import com.clas.liu.myapplication.model.impl.SquareModel;
import com.clas.liu.myapplication.presenter.i.ISquarePresenter;
import com.clas.liu.myapplication.view.fragment.impl.BaseFragment;
import com.clas.liu.myapplication.view.fragment.impl.SquareFragment;

import java.lang.ref.WeakReference;

/**
 * Created by liu on 2019/5/4.
 */

public class SquarePresenter extends BaseFragmentPresenter<SquareModel,SquareFragment,SquareEvent> implements ISquarePresenter {

    public SquarePresenter(SquareFragment view) {
        super(view);
    }

    @Override
    public void getInfo(int page_no, int page_size) {
        mModel.getInfo(page_no,page_size);
    }

    @Override
    protected SquareModel getModel(BaseFragmentModel.OnEventReceiveListener listener) {
        return new SquareModel(this);
    }

    @Override
    public void eventReceiveOnUiThread(Message msg) {

    }

    @Override
    public void eventReceive(SquareEvent event, int what) {
        if (what == SquareEvent.GET_INFO_OK) {
            mView.InfoReturn(event.getRoot().getCode(),event.getRoot().getData());
        }else if (what == SquareEvent.GET_INFO_FAIL) {
            mView.FailBecauseNetReturn(what);
        }
    }
}
